feat: usage anomaly detector for 5-minute per-developer traffic spikes (#476)#587
Merged
greatest0fallt1me merged 1 commit intoJun 29, 2026
Conversation
Add a background worker that compares each developer's latest completed 5-minute usage window against the mean of the trailing 12 windows and emits usage.anomaly.detected when traffic exceeds a configurable multiplier.
|
@ironhood Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #476
Adds a background worker that detects per-developer usage anomalies by comparing the most recently completed 5-minute traffic window against a rolling baseline (mean of the trailing 12 windows). When call volume exceeds
baseline × multiplier, the worker emits ausage.anomaly.detecteddomain event, which fans out to matching developer webhook subscriptions.src/services/anomalyService.ts— pure detection logic, PostgreSQL window aggregation, deduplication, and event emissionsrc/workers/anomalyDetector.ts— interval job with overlap guard and graceful shutdown hooksdocs/usage-anomaly-detector.md— configuration, event payload, and metrics referenceDesign
currentCalls > baselineMean × USAGE_ANOMALY_MULTIPLIER(default 5×)(developerId, windowStart)to avoid duplicate alerts within a windowgetOrCreateRequestIdConfiguration
USAGE_ANOMALY_DETECTOR_ENABLEDtrueUSAGE_ANOMALY_MULTIPLIER5USAGE_ANOMALY_POLL_INTERVAL_MS300000USAGE_ANOMALY_WINDOW_MS300000USAGE_ANOMALY_BASELINE_WINDOWS12Event payload (
usage.anomaly.detected){ "windowStart": "2026-06-01T12:00:00.000Z", "windowEnd": "2026-06-01T12:05:00.000Z", "currentCalls": 100, "baselineMean": 10, "multiplier": 5, "ratio": 10, "windowMs": 300000 }